<cfoutput><CFQUERY NAME="getclient" DATASOURCE="#dsn#">
select *
from tblcustomers
where CustomerNum = <cfqueryparam cfsqltype="cf_sql_integer" value="#accountnumber#">

</CFQUERY>

<cfset today = now()>
<cfset mytime = timeformat(now(), "hh:mm:ss tt")>



<CFQUERY NAME="getprod" DATASOURCE="#dsn#">
select *
from tblproducts
where ProdID = '#prodid#'
</CFQUERY>


<cfset session.ProdID = "#getprod.prodid#">

<cflocation url="index.cfm">


<!---<cfif not isdefined("session.ReceiptNum")>
<cfinclude template="createinvoice.cfm">



</cfif>



<CFQUERY NAME="getprod" DATASOURCE="#dsn#">
select *
from tblproducts
where ProdID = '#ProdID#'
</CFQUERY>


<cfif #getprod.Tax# is 1>
<cfset caltax = #getprod.TaxAmount# / 100>
 <cfset mytax = #getprod.Price# * #caltax#>
 <cfelse>
  <cfset mytax = 0>
</cfif>
 
<cfquery datasource="#dsn#">
INSERT INTO tbltransactions(ReceiptNum, ProdID, Price, TransDate, TransType, ProductName, TaxAmount)
VALUES(#session.ReceiptNum#, 
'#ProdID#', 
#getprod.Price#, 
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#today#">,
'Purchase',
'#getprod.ProductName#',
#mytax#)
</cfquery>

<CFQUERY NAME="Recordset1" DATASOURCE="#dsn#">
select sum(Price) as total, sum(TaxAmount) as taxtotal
from tbltransactions
where ReceiptNum = #session.ReceiptNum#
</CFQUERY>
<!---update main invoice with total amount-------------------->

<cfset mytaxtotal = #Recordset1.total# + #Recordset1.taxtotal#>

<cfquery datasource="#dsn#">
update tblorders
set Amount = #mytaxtotal#
where ReceiptNum = #session.ReceiptNum# 
</cfquery>
<!---take from inventory......................................................--->


<cfif #getprod.Qty# gte 1>
<cfset myqty = #getprod.Qty# - 1>
<cfelse>
<cfset myqty = 0>

</cfif>

<cfquery datasource="#dsn#">
update tblproducts
set Qty = #myqty#
where ProdID = '#ProdID#'
</cfquery>




<cfquery datasource="#dsn#">
INSERT INTO tblinventory(ReceiptNum, ProdID, Price, DateIn, DODAAC, Username, Terminal, Qty, TransType, Cost)
VALUES(#session.ReceiptNum#, 
'#ProdID#', 
#getprod.Price#, 
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#today#">,
<cfif isdefined("session.DODAAC")>#session.DODAAC#<cfelse>null</cfif>,
'#session.username#',
#session.terminal#,
#getprod.Qty#,
'SALE',
#getprod.Cost#)
</cfquery>





<CFQUERY DATASOURCE="#dsn#">
INSERT INTO tbltranslog (Code, ReceiptNum, TransDate, TransTime, username, ProdID, Amount)
VALUES (
'A',
#session.ReceiptNum#,
<cfqueryparam cfsqltype="cf_sql_date" value="#today#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#mytime#">,
'#SESSION.USERNAME#',
'#ProdID#',
#mytaxtotal#

)
</CFQUERY>






<cflocation url="index.cfm">

--->
</cfoutput>
